# -*- coding: utf-8 -*-
'''
Created on Jan 10, 2021

@author: yl
'''

from FFT_Interpolation import *
from WangJiaNing_FFT import x, tau0, N

f = 8
phi = 0

sig = np.cos(2*np.pi*f*x + phi)
window_gaussian = signal.gaussian(N, std=N/4)
sig = sig * window_gaussian
# zero_padd = np.zeros(4096-N)
# sig = np.concatenate((sig,zero_padd))
print(len(sig))
freqline, sig_FFT, sig_freq, sig_phase = FFT_cal(sig, tau0)
print(sig_freq.argmax())
print(sig_freq[sig_freq.argmax()])

plt.subplot(3,1,1)
plt.plot(sig, label='Original Signal', color='blue')
# plt.title("Time Domain Signal")
plt.ylabel("Amplitude")
plt.xlabel("Samples")
plt.grid(which='major', axis='both')

plt.subplot(3,1,2)
plt.stem(sig_freq, linefmt='b', markerfmt='bo', basefmt=" ", label='Magnitude Spectrum', use_line_collection=True)
legend = plt.legend(loc='upper right')
# plt.title("Magnitude Spectrum")
plt.ylabel("Magnitude")
plt.xlabel("Frequency")
# plt.xlim(0,60)
plt.grid(which='major', axis='both')

plt.subplot(3,1,3)
plt.stem(sig_phase, linefmt='b', markerfmt='bo', basefmt=" ", label='Phase Spectrum', use_line_collection=True)
# plt.plot(sig_phase)
legend = plt.legend(loc='upper right')
# plt.title("Magnitude Spectrum")
plt.ylabel("Phase")
plt.xlabel("Frequency")
# plt.xlim(0,60)
plt.grid(which='major', axis='both')

plt.tight_layout()
plt.show()